home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-20 / rs0422.zip / CONFIGUR / USERS.C < prev    next >
C/C++ Source or Header  |  1990-10-26  |  11KB  |  401 lines

  1. /*
  2.  * Copyright 1988 by the Radio Amateur Telecommunications Society
  3.  * and Thomas A. Moulton, W2VY
  4.  *
  5.  * This software may only be modified, copied, distributed or
  6.  * executed for non-profit purposes by individuals operating
  7.  * systems in the Amateur Radio Service.  Credit to the
  8.  * author(s) and to the Radio Amateur Telecommunications Society
  9.  * must be made in modules where RATS provided software is used,
  10.  * and in any announcements and documentation.  
  11.  *
  12.  * As a non-profit, research and development organization,  the
  13.  * Radio Amateur Telecommunications Society distributes software
  14.  * in both executable and source forms.  This policy is in place
  15.  * to encourage the development and distribution of OSI-based,
  16.  * networking tools.  In order to protect the interests of the
  17.  * Society and the authors, we have placed some conditions
  18.  * of use on the software.  Other groups are encouraged
  19.  * to place the same or similar guidelines on
  20.  * software they produce.
  21.  *
  22.  * The Radio Amateur Telecommunications Society reserves the right
  23.  * to specify and alter the terms under which software provided by
  24.  * the Society may be used.  This policy is consistent with the 
  25.  * objective of uniform and consistent "Open Systems Interconnections."
  26.  * 
  27.  * All acceptable Amateur Radio related uses of this software
  28.  * will be outlined in the "ROSE Implementer's Guide".  Individuals
  29.  * or organizations wishing to add to, or modify the provisions of
  30.  * the guide to accommodate local or evolutionary requirements
  31.  * should document the proposed change(s) and forward them to the
  32.  * Society.  If accepted, written notification will be provided by
  33.  * the Society to the submitting organization or individual(s).
  34.  * The Society will then issue a "ROSE Implementer's Guide Change
  35.  * Notice".  Periodically, the Society will re-issue the "ROSE 
  36.  * Implementer's Guide" and incorporate the text of the change 
  37.  * notices.  This procedure has been put in to place to ensure
  38.  * compatibility between systems and to ensure their "Openness"
  39.  * and interoperability.
  40.  *
  41.  * No part of this software may be used in other packages 
  42.  * without prior authorization from the author or the Society.  
  43.  * Software incorporating this module, all or in part, must be 
  44.  * provided to the Society prior to distribution or use by
  45.  * anyone not directly involved in testing of the revised  
  46.  * environment.  Current releases of the combined software must
  47.  * be provided to the Society in both source and executable
  48.  * forms.  Adequate documention to produce an executable module 
  49.  * from the provided source must also be included.
  50.  *
  51.  * Non-Amateur Radio non-profit uses may be authorized on a case
  52.  * by case basis.  Inquiries for such use may be made in writing
  53.  * to the Society. Non-commercial uses consistent with the
  54.  * general principles of Open Systems Interconnection Reference
  55.  * Model will be generally considered with favor.
  56.  *
  57.  * Commercial licensing of the software is also available based
  58.  * on normal commercial terms.  Licensing inquiries should be
  59.  * directed to the Society.  Commercial licensing of the standard
  60.  * software will be done in situations which materially benefit
  61.  * the Amateur Radio Packet Network.  Additional licensing is
  62.  * reserved by the individual authors.
  63.  * 
  64.  * The Radio Amateur Telecommunications Society provides this software
  65.  * on an "as is" basis.  The Society assumes no liability for
  66.  * loss incurred through the use of this software.  Amateur Radio
  67.  * use of this software implies non-commercial and voluntary 
  68.  * development, deployment and use of this software in a "Amateur",
  69.  * non-commercial service.  Commercial users are encouraged to
  70.  * inspect their copies of the source code.  Source code modification
  71.  * licenses are available if a combined Object and Source Code
  72.  * license was not originally established.
  73.  * 
  74.  * The Society may be contacted by writing or calling at:
  75.  * 
  76.  * The Radio Amateur Telecommunications Society 
  77.  * 206 North Vivyen Street.
  78.  * Bergenfield, New Jersey 07621
  79.  *
  80.  * Telephone: 201-387-8896
  81.  *
  82.  */
  83. #include "data.h"
  84. #include "buffer.h"
  85. #include "iface.h"
  86. #include "timer.h"
  87. #include "ax25.h"
  88. #include "ax25l2.h"
  89. #include "l3struc.h"
  90. #include "x25cause.h"
  91. #include "l3calls.h"
  92. #include "tx.h"
  93. #include "config.h"
  94. #include "upfcn.h"
  95.  
  96. int NULLFCN(), clr_users(), con_users(), recv_boot();
  97. int send_users(), rst_boot(), unload_ok();
  98.  
  99. struct upfcn users={
  100.     {{0xaa, 0xa6, 0x8a, 0xa4, 0xa6, 0x40}, {0x00}}, /* USERS-0 */
  101.     rst_boot, clr_users, con_users, recv_boot,
  102.     send_users, NULLFCN, unload_ok,
  103.     "USERS  - ROSE Switch User List Display, Version 1.4\r"
  104. };
  105.  
  106. extern struct datastr *l2_user_info, l2_info;
  107. extern struct axcb *links;
  108. extern int L3TRIED[16];
  109. extern unsigned char node_addr[16];
  110. extern struct VCS *pending_calls;
  111. extern unsigned int MEMSIZ, HEAPUSD;
  112. extern char str_work[128];
  113.  
  114. struct datastr *mkpkt(), *bappstr();
  115. unsigned char *malloc(), *calloc();
  116. void free();
  117.  
  118. struct datastr *user_in;
  119. struct VCS *user_llcn;
  120.  
  121. int
  122. con_users(vc)
  123. register struct VCS *vc;
  124. {
  125.     vc->next = user_llcn;    /* This works even when _llcn is NULL */
  126.     user_llcn = vc;
  127.  
  128.     vc=vc->peer;
  129.     if (!vc) return;
  130.     (*vc->SEND)(vc,info_pkt());
  131. }
  132.  
  133. int
  134. clr_users(vc,c)
  135. struct VCS *vc;
  136. int c;
  137. {
  138.     register struct VCS *vcp;
  139.  
  140.     if (user_llcn == vc) user_llcn = vc->next; /* First item */
  141.     else {
  142.         vcp = user_llcn;
  143.         while (vcp->next && vcp->next != vc) vcp = vcp->next;
  144.         if (vcp->next == vc) vcp->next = vc->next;
  145.     }
  146.     vc->next = NULL;
  147.     set_p(vc, P1, 0);
  148. }
  149.  
  150. int
  151. send_users(vc, pkt)
  152. struct VCS *vc;
  153. struct datastr *pkt;
  154. {
  155.     static int i, j;
  156.     static unsigned char *mem;
  157.     register struct VCS *vcx;
  158.     static struct ax25_addr stn;
  159.     static struct axcb *axcb;
  160.  
  161.     vc_queue_data(vc,pkt);
  162.     while ((user_in = vc->tx_queue)) /* There is stuff waiting */ {
  163.         vc->tx_queue = user_in->next;
  164.         free_buffer(user_in);
  165.         user_in = new_buffer(128);
  166.         bappstr(user_in, "\rUser List for ");
  167.         call_strx(&L3CALL[0], str_work);
  168.         bappstr(user_in, str_work);
  169.         bappch(user_in,0x20);
  170.         x121_strx(node_addr, str_work);
  171.         bappstr(user_in, str_work);
  172.         bappstr(user_in,"\rMemory Size is: ");
  173.         putdec(user_in, MEMSIZ, 6);
  174.         bappstr(user_in," Bytes\rMemory Used is: ");
  175.         putdec(user_in, HEAPUSD, 6);
  176.         bappstr(user_in," Bytes\rEPROM Checksum: ");
  177.         mem = 0;
  178.         j = 0;
  179.         while ((int)mem >= 0) j += *mem++;
  180.         putxch(user_in, j&0x0ff);
  181.         bappstr(user_in,"h\r\r");
  182.         (*vc->peer->SEND)(vc->peer, user_in);
  183.         user_in = new_buffer(1024);
  184.         axcb=links;
  185.         while (axcb) /* For all links */ {
  186.             call_strx(&axcb->path[0], str_work);
  187.             bappstr(user_in, str_work);
  188.             if (axcb->rpid == PID_X25) {
  189.                 bappstr(user_in," X.25 Trunk (R");
  190.                 bappch(user_in,axcb->R+0x30);
  191.                 if (vcx=axcb->llcn) bappstr(user_in,") with the following connections:\r");
  192.                 else bappstr(user_in,") with no connections.\r");
  193.                 while (vcx) {
  194.                     prt_vc(vcx);
  195.                     vcx=vcx->next;
  196.                 }
  197.             } else if (axcb->rpid == PID_TNC || axcb->rpid == 0) {
  198.                 bappstr(user_in," AX25L2 User Linked to ");
  199.                 if (axcb->llcn) /* Have my VC */ {
  200.                     if (axcb->llcn->peer) /* Have peer */ {
  201.                         get_nsap(axcb->llcn->peer, &stn);
  202.                          call_strx(&stn, str_work);
  203.                         bappstr(user_in, str_work);
  204.                         bappstr(user_in," @ ");
  205.                         x121_strx(axcb->llcn->peer->addr, str_work);
  206.                         bappstr(user_in, str_work);
  207.                     } else  bappstr(user_in, "*** NO PEER ***");
  208.                 } else bappstr(user_in, "*** NO VC ***");
  209.                 bappstr(user_in,"\r");
  210.             } else {
  211.                 bappstr(user_in, "*** Unknown Protocol ID ");
  212.                 putxch(user_in, axcb->rpid);
  213.                 bappstr(user_in, " ***\r");
  214.             }
  215.             axcb=axcb->next;
  216.         }
  217.         if (vcx=pending_calls) {
  218.             bappstr(user_in,"\rPending Calls:\r");
  219.             while (vcx) {
  220.                 prt_vc(vcx);
  221.                 vcx=vcx->next;
  222.             }
  223.         } else bappstr(user_in,"\rThere are no calls Pending.\r");
  224.  
  225.         bappstr(user_in,"\rThe Following X.25 Trunks are listed as Out of Order:\r");
  226.         j=0;
  227.         for (i=1;i<16;i++) /* For all configured links */ {
  228.             if (L3TRIED[i] > 0) /* Bad */ {
  229.                 j=1;
  230.                 call_strx(&L3CALL[i], str_work);
  231.                 bappstr(user_in, str_work);
  232.                 bappstr(user_in, " With ");
  233.                 put_hms(user_in, L3TRIED[i]);
  234.                 bappstr(user_in," Hours Left.\r");
  235.             }
  236.         }
  237.         if (!j) bappstr(user_in,"<None> - All Links Operational\r");
  238.  
  239.         (*vc->peer->SEND)(vc->peer, user_in);
  240.         user_in = NULL;
  241.     }
  242.     return 256;    /* We are never busy! */
  243. }
  244.  
  245. /*
  246. User List for N2DSY-3 3100201744
  247.  
  248. KD6TH-4  AX25L2 User linked to KB1BD-4 @ 3100609443
  249. WB2JQR-3 X.25 Trunk with the following connections:
  250. KB1BD-5  @ 3100609443 P4 D1 > KD6TH-4  @ 3100201744
  251. WB2DRD-3 @ 3100609530 P4 D1 < W2VY     @ 3100201478
  252. W2VY-6   X.25 Trunk with the following connections:
  253. W2VY     @ 3100201478 P4 D1 > WB2DRD-3 @ 3100609530
  254. KD6TH-6  X.25 Trunk with no connections active.
  255.  
  256. The Following X.25 Trunks are listed as Out of Order:
  257. N2ELC-3
  258.  
  259. */
  260.  
  261. x121_strx(x121, str)
  262. char x121[];
  263. register char *str;
  264. {
  265.     static int l;
  266.     int x121_str();
  267.  
  268.     l = x121_str(x121, str);
  269.     str += l;
  270.     while (l<15) {
  271.         *str++ = 0x20;
  272.         l++;
  273.     }
  274.     *str = NULL;
  275. }
  276.  
  277. call_strx(stn, str)
  278. struct ax25_addr *stn;
  279. register char *str;
  280. {
  281.     static int j;
  282.     int call_str();
  283.  
  284.     j=call_str(stn, str);
  285.     if (str[j-1] == '0' && str[j-2] == '-') j -= 2;
  286.     str += j;
  287.     while (j<9) {
  288.         *str++ = 0x20;
  289.         j++;
  290.     }
  291.     *str = NULL;
  292. }
  293.  
  294. putdec(bp, val, w)
  295. struct datastr *bp;
  296. unsigned int val;
  297. int w;
  298. {
  299.     static char z[10];
  300.     static unsigned int v, u10;
  301.     static int i;
  302.  
  303.     u10 = 10;
  304.     for (i=0;i<10;i++) z[i]=' ';
  305.     z[9]=0;
  306.     v=val;
  307.     for (i=8;i>=0, v!=0;i--) /* Stuff one digit at a time */ {
  308.         z[i] = '0' + (v - (v/u10)*u10);
  309.         v = v / 10;
  310.     }
  311.     bappstr(bp, &z[9-w]);
  312. }
  313.  
  314. #if 0
  315. putdec(bp, val)
  316. struct datastr *bp;
  317. unsigned char val;
  318. {
  319.     static char z[4];
  320.     static unsigned char v;
  321.  
  322.     z[0]=' ';
  323.     z[1]=' ';
  324.     z[2]=' ';
  325.     z[3]=0;
  326.     v=val;
  327.     if (v>99) {
  328.         z[0] = (v/100) + '0';
  329.         v = v - ((z[0]-'0') * 100);
  330.         z[1] = (v/10) + '0';
  331.         v = v - ((z[1]-'0') * 10);
  332.     }
  333.     if (v>9) {
  334.         z[1] = (v/10) + '0';
  335.         v = v - ((z[1]-'0') * 10);
  336.     }
  337.     z[2] = v + '0';
  338.     bappstr(bp, z);
  339. }
  340. #endif
  341.  
  342. put_hms(bp, val)
  343. struct datastr *bp;
  344. int val;
  345. {
  346.     static char z[9];
  347.     static int v, i;
  348.  
  349.     for (i=0;i<9;i++) z[i]='0';
  350.     z[2]=z[5]=':';
  351.     z[8]=0;
  352.     v=val;
  353.     i = v/3600;
  354.     if (i>0) {
  355.         z[0] = (i/10) + '0';
  356.         z[1] = (i - ((i/10) * 10)) +'0';
  357.     }
  358.     v = v - (i*3600);
  359.     i = v/60;
  360.     if (i>0) {
  361.         z[3] = (i/10) + '0';
  362.         z[4] = (i - ((i/10) * 10)) +'0';
  363.     }
  364.     v = v - (i*60);
  365.     i = v;
  366.     if (i>0) {
  367.         z[6] = (i/10) + '0';
  368.         z[7] = (i - ((i/10) * 10)) +'0';
  369.     }
  370.     bappstr(bp,z);
  371. }
  372.  
  373. prt_vc(vcx)
  374. register struct VCS *vcx;
  375. {
  376.     static struct ax25_addr stn;
  377.  
  378.     get_nsap(vcx,&stn);
  379.     call_strx(&stn, str_work);
  380.     bappstr(user_in, str_work);
  381.     bappstr(user_in," @ ");
  382.     x121_strx(vcx->addr, str_work);
  383.     bappstr(user_in, str_work);
  384.     bappstr(user_in,"(");
  385.     putdec(user_in, vcx->lcn, 3);
  386.     bappstr(user_in," P");
  387.     bappch(user_in, vcx->P+0x31);
  388.     bappstr(user_in," D");
  389.     bappch(user_in, vcx->D+0x31);
  390.     bappstr(user_in, vcx->alt ? ") <-- " : ") --> ");
  391.     if (vcx->peer) {
  392.         get_nsap(vcx->peer,&stn);
  393.         call_strx(&stn, str_work);
  394.         bappstr(user_in, str_work);
  395.         bappstr(user_in," @ ");
  396.         x121_strx(vcx->peer->addr, str_work);
  397.         bappstr(user_in, str_work);
  398.     } else bappstr(user_in, "*** NO PEER ***");
  399.     bappstr(user_in,"\r");
  400. }
  401.